/**
 * 
 */
package org.springside.examples.miniweb.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * @author Bob
 * 
 */
@Entity
// 表名与类名不相同时重新定义表名.
@Table(name = "acct_company")
// 默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Company extends IdEntity {

	private String name;

	private String manager;

	private Long parentId;

	private int level;

	private String levelName;

	private int valid;

	/**
	 * @return the name
	 */
	// 字段非空且唯一, 用于提醒Entity使用者及生成DDL.
	@Column(nullable = false, unique = true)
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the parentId
	 */
	@Column(nullable = false)
	public Long getParentId() {
		return parentId;
	}

	/**
	 * @param parentId
	 *            the parentId to set
	 */
	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	/**
	 * @return the valid
	 */
	@Column
	public int getValid() {
		return valid;
	}

	/**
	 * @param valid
	 *            the valid to set
	 */
	public void setValid(int valid) {
		this.valid = valid;
	}

	/**
	 * @return the level
	 */
	@Column
	public int getLevel() {
		return level;
	}

	/**
	 * @param level
	 *            the level to set
	 */
	public void setLevel(int level) {
		this.level = level;
	}

	@Transient
	public String getLevelName() {
		switch (level) {
		case 1:
			levelName = "总公司";
			break;
		case 2:
			levelName = "省公司";
			break;
		case 3:
			levelName = "市公司";
			break;
		}
		return levelName;
	}

	/**
	 * @param levelName
	 *            the levelName to set
	 */
	public void setLevelName(String levelName) {
		this.levelName = levelName;
	}

	/**
	 * @return the manager
	 */
	public String getManager() {
		return manager;
	}

	/**
	 * @param manager
	 *            the manager to set
	 */
	@Column
	public void setManager(String manager) {
		this.manager = manager;
	}
}
